########################################
# Events for Mali
#
# written by Johan Andersson
########################################

namespace = flavor_mal
normal_or_historical_nations = yes

# Malian Authority Under Threat
country_event = {
	id = flavor_mal.1
	title = flavor_mal.1.t
	desc = flavor_mal.1.d
	picture = LIBERUM_VETO_eventPicture
	fire_only_once = yes

	trigger = {
		tag = MAL
		NOT = { stability = 0 }
		NOT = { is_year = 1550 }
		owns = 1112
		owns = 1113
		owns = 1116
		owns = 2239
		NOT = { exists = JOL }
		NOT = { has_dlc = "Origins" }	#Mali gets a whole disaster instead for its authority question
	}

	mean_time_to_happen = {
		months = 36
	}
	
	
	option = { 
		name = flavor_mal.1.a
		ai_chance = { factor = 90 }
		
		1112 = { nationalist_rebels = 2	}
		1113 = { nationalist_rebels = 2	}
		1116 = { nationalist_rebels = 2	}
		2239 = { nationalist_rebels = 2	}
	}
	option = {
		name = flavor_mal.1.b	
		ai_chance = { factor = 10 }
		
		release = JOL
	}
	
	
}

########################################
# Events for Mali
#
# written by Henrik Lohmander
########################################

# Rise of Fulo
province_event = {
	id = flavor_mal.2
	title = flavor_mal.2.t
	desc = flavor_mal.2.d
	picture = HORDE_ON_HORSEBACK_eventPicture
	fire_only_once = yes

	trigger = {
		province_id = 2238
		NOT = { exists = FUL }
		is_year = 1470
		tekrur_area = {
			is_empty = yes
		}
	}

	mean_time_to_happen = {
		months = 36
	}
	
	immediate = {
		hidden_effect = {
			every_province = {
				limit = {
					OR = {
						area = tekrur_area
						province_id = 1112 #Trarza
						province_id = 1120 #Bambuk
						province_id = 2238 #Kantor
						province_id = 2243 #Termes
						province_id = 2245 #Wagadu
						province_id = 2246 #Bagena
					}
				}
				add_core = FUL
				if = {
					limit = {
						owner = {
							NOT = { has_country_flag = fulani_info_flag }
						}
					}
					owner = {
						country_event = { id = flavor_mal.3 }
						set_country_flag = fulani_info_flag
					}
				}
				every_province = {
					limit = {
						OR = {
							area = tekrur_area
							province_id = 1112 #Trarza
							province_id = 1120 #Bambuk
							province_id = 2238 #Kantor
							province_id = 2243 #Termes
							province_id = 2245 #Wagadu
							province_id = 2246 #Bagena
						}
						is_empty = no
					}
					add_province_modifier = {
						name = "mal_fulani_migration"
						duration = 3650
					}
					change_culture = fulani
				}
				baghena_area = {
					limit = {
						culture = fulani
					}
					if = {
						limit = {
							is_core = SOF
							NOT = { owned_by = SOF }
						}
						remove_core = SOF
					}
					add_core = ZAF
				}
			}
		}
	}
	
	option = {
		name = flavor_mal.2.a
		every_province = {
			limit = {
				OR = {
					area = tekrur_area
					province_id = 1112 #Trarza
					province_id = 1120 #Bambuk
					province_id = 2238 #Kantor
					province_id = 2243 #Termes
					province_id = 2245 #Wagadu
					province_id = 2246 #Bagena
				}
				is_empty = yes
			}
			cede_province = FUL
		}
		hidden_effect = {
			FUL = {
				define_ruler = {
					name = "Koli Tengella"
					dynasty = "Denianke"
					change_mil = 4
					claim = 100
				}
				if = {
					limit = {
						has_dlc = "Rights of Man" 
					}
					add_ruler_personality_ancestor = { key = conqueror }
				}
				adopt_reform_progress = ROOT
				capital_scope = {
					build_to_forcelimit = {
						infantry = 0.7
						cavalry = 0.3
					}
					add_base_tax = 3
					add_base_production = 3
					add_base_manpower = 2
				}
				add_manpower = 10
				add_treasury = 300
			}
		}
	}
	
	
	option = {	#Switch tag to Fulo
		name = flavor_mal.2.b
		trigger = {
			owner = {
				ai = no
			}
		}
		every_province = {
			limit = {
				OR = {
					area = tekrur_area
					province_id = 1112 #Trarza
					province_id = 1120 #Bambuk
					province_id = 2238 #Kantor
					province_id = 2243 #Termes
					province_id = 2245 #Wagadu
					province_id = 2246 #Bagena
				}
				is_empty = yes
			}
			cede_province = FUL
		}
		hidden_effect = {
			FUL = {
				define_ruler = {
					name = "Koli Tengella"
					dynasty = "Denianke"
					change_mil = 4
					claim = 100
				}
				if = {
					limit = {
						has_dlc = "Rights of Man" 
					}
					add_ruler_personality_ancestor = { key = conqueror }
				}
				adopt_reform_progress = ROOT
				capital_scope = {
					build_to_forcelimit = {
						infantry = 0.7
						cavalry = 0.3
					}
					add_base_tax = 3
					add_base_production = 3
					add_base_manpower = 2
				}
				add_manpower = 10
				add_treasury = 300
			}
		}
		owner = {
			switch_tag = FUL
		}
	}
}

# Event to send to other province owners of the area when Fulo is formed.
country_event = {
	id = flavor_mal.3
	title = flavor_mal.2.t
	desc = flavor_mal.2.d
	picture = HORDE_ON_HORSEBACK_eventPicture
	
	is_triggered_only = yes
	
	trigger = {
		NOT = { owns = 2238 }
	}

	option = {
		name = flavor_nub.2.a
		tooltip = {
			every_province = {
				limit = {
					OR = {
						area = tekrur_area
						province_id = 1112 #Trarza
						province_id = 1120 #Bambuk
						province_id = 2238 #Kantor
						province_id = 2243 #Termes
						province_id = 2245 #Wagadu
						province_id = 2246 #Bagena
					}
				}
				add_core = FUL
			}
		}
	}
}


# The Wangara and the Portuguese
country_event = {
	id = flavor_mal.4
	title = flavor_mal.4.t
	desc = flavor_mal.4.d
	picture = ECONOMY_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MAL
		exists = POR
		is_year = 1455 #ie after the initial, more violent encounters.
		any_owned_province = {
			has_port = yes
			has_discovered = POR
		}
	}
	
	mean_time_to_happen = {
		months = 180
	}

	option = {
		name = flavor_mal.4.a
		add_country_modifier = {
			name = mal_portuguese_traders
			duration = -1
		}
	}
}

#Portuguese Traders Meddle in Local Politics.
country_event = {
	id = flavor_mal.5
	title = flavor_mal.5.t
	desc = flavor_mal.5.d
	picture = ACCUSATION_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MAL
		exists = POR
		is_year = 1465
		has_country_modifier = mal_portuguese_traders
		any_owned_province = {
			has_port = yes
		}
	}
	
	mean_time_to_happen = {
		months = 300
	}

	option = {
		name = flavor_mal.5.a	#Act decisively to limit Portuguese influence
		add_country_modifier = {
			name = mal_wangaras_upset
			duration = -1
		}
		remove_country_modifier = mal_portuguese_traders
		POR = {
			add_opinion = { who = MAL modifier = trade_conflict }
		}
	}
	
	option = {
		name = flavor_mal.5.b	#The problem lies with the disloyal chiefs
		add_stability_or_adm_power = yes
		every_owned_province = {
			limit = {
				OR = {
					has_port = yes
					area = cap_verde_area
					province_id = 2238
					province_id = 1117
					province_id = 1120
				}
	 		}
			add_province_modifier = {
				name = "mal_portuguese_meddling"
				duration = 3650
			}
		}
	}
}

#Increasing Islamisation of the Aristocracy
country_event = {
	id = flavor_mal.6
	title = flavor_mal.6.t
	desc = flavor_mal.6.d
	picture = MUSLIM_ANIMIST_DISPUTE_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MAL
		religion_group = muslim
	}
	
	mean_time_to_happen = {
		months = 12
	}

	option = {
		name = flavor_mal.6.a	#Convert our people!
		add_piety = 0.15
		if = {
			limit = {
				NOT = { has_completed_all_reforms_trigger = yes }
			}
			add_reform_progress_small_effect = yes
		}
		add_country_modifier = {
			name = mal_islamisation_of_the_aristocracy
			duration = -1
		}
		if = {
			limit = {
				has_dlc = "Origins"
			}
			custom_tooltip = flavor_mal.6.a.tt
			hidden_effect = {
				set_country_flag = mal_decide_for_conversion
			}
		}
	}
	
	option = {
		name = flavor_mal.6.b	#Let us not rock the boat.
		add_stability_or_adm_power = yes
		add_piety = -0.15
		if = {
			limit = {
				has_dlc = "Origins"
			}
			custom_tooltip = flavor_mal.6.b.tt
			hidden_effect = {
				set_country_flag = mal_decide_for_tolerance
			}
		}
	}
}

#Unsafe Roads
country_event = {
	id = flavor_mal.7
	title = flavor_mal.7.t
	desc = flavor_mal.7.d
	picture = VILLAGE_BURNING_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MAL
		is_year = 1480
		NOT = { is_year = 1550  }
		OR = {
			is_neighbor_of = FUL
			any_owned_province = {
				has_province_modifier = mal_fulani_migration
			}
		}
	}
	
	mean_time_to_happen = {
		months = 210
	}

	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_capital = no
					any_neighbor_province = {
						is_capital = no
					}
				}
				set_province_flag = mali_roads_unsafe
			}
			random_owned_province = {
				limit = {
					is_capital = no
					any_neighbor_province = {
						is_capital = no
					}
					NOT = { has_province_flag = mali_roads_unsafe }
				}
				set_province_flag = mali_roads_unsafe
			}
			random_owned_province = {
				limit = {
					is_capital = no
					any_neighbor_province = {
						is_capital = no
					}
					NOT = { has_province_flag = mali_roads_unsafe }
				}
				set_province_flag = mali_roads_unsafe
			}
			random_owned_province = {
				limit = {
					is_capital = no
					any_neighbor_province = {
						is_capital = no
					}
					NOT = { has_province_flag = mali_roads_unsafe }
				}
				set_province_flag = mali_roads_unsafe
			}
			random_owned_province = {
				limit = {
					is_capital = no
					any_neighbor_province = {
						is_capital = no
					}
					NOT = { has_province_flag = mali_roads_unsafe }
				}
				set_province_flag = mali_roads_unsafe
			}
		}
	}
	
	option = {
		name = flavor_mal.7.a
		ai_chance = { factor = 40 }
		every_owned_province = {
			limit = {
				has_province_flag = mali_roads_unsafe
			}
			add_local_autonomy = 60
			add_province_modifier = {
				name = "mal_unsafe_roads"
				duration = 365
			}
			clr_province_flag = mali_roads_unsafe
		}
	}
	
	option = {
		name = flavor_mal.7.b
		ai_chance = { factor = 20 }
		add_adm_power = -100
		every_owned_province = {
			limit = {
				has_province_flag = mali_roads_unsafe
			}
			add_province_modifier = {
				name = "mal_unsafe_roads"
				duration = 915
			}
			clr_province_flag = mali_roads_unsafe
		}
	}
	
	option = {
		name = flavor_mal.7.c
		ai_chance = { factor = 40 }
		every_owned_province = {
			limit = {
				has_province_flag = mali_roads_unsafe
			}
			add_province_modifier = {
				name = "mal_unsafe_roads"
				duration = 3650
			}
			clr_province_flag = mali_roads_unsafe
		}
	}
}

#Rise of Kaabu
country_event = {
	id = flavor_mal.8
	title = flavor_mal.8.t
	desc = flavor_mal.8.d
	picture = CIVIL_WAR_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		tag = MAL
		NOT = { exists = KBU }
		is_year = 1475
		religion_group = muslim
		any_owned_province = {
			is_core = KBU
			culture = senegambian
			religion = shamanism
			is_capital = no
		}
		NOT = { has_country_flag = mal_appeased_kaabu }
	}
	
	mean_time_to_happen = {
		months = 450
		
		modifier = {
			factor = 0.7
			any_owned_province = {
				is_core = KBU
				has_province_modifier = mal_unsafe_roads
			}
		}
		modifier = {
			factor = 0.7
			any_owned_province = {
				is_core = KBU
				has_province_modifier = mal_portuguese_meddling
			}
		}
		modifier = {
			factor = 0.7
			has_country_modifier = mal_islamisation_of_the_aristocracy
		}
		modifier = {
			factor = 0.7
			has_disaster = decline_of_mali
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_core = KBU
					culture = senegambian
					religion = shamanism
					is_capital = no
				}
			set_province_flag = centre_of_kaabu_rebelion
			}
			set_country_flag = kaabu_broke_into_rebelion
		}
	}
	
	option = {
		name = flavor_mal.8.a
		ai_chance = { factor = 90 }
		every_owned_province = {
			limit = {
				is_core = KBU
				culture = senegambian
				not = { has_province_flag = centre_of_kaabu_rebelion }
			}
			spawn_rebels = {
				type = nationalist_rebels
				size = 1
			}
		}
		random_owned_province = {
			limit = {
				has_province_flag = centre_of_kaabu_rebelion
			}
			spawn_rebels = {
				type = nationalist_rebels
				size = 2
				leader = "Sami Koli Jeenung"
			}
			clr_province_flag = centre_of_kaabu_rebelion
		}
	}
	
	option = {
		name = flavor_mal.8.b
		ai_chance = { factor = 10 }
		release = KBU
		KBU = {
			define_ruler = {
				name = "Sama Koli"
				dynasty = "Jeenung"
				claim = 100
			}
		}
	}

}

########################################
# Events for Mali
#
# written by Ogulcan Yildirim
########################################

# Decline of Mali Disaster
# Disaster start
country_event = {
	id = flavor_mal.9
	title = flavor_mal.9.t
	desc = flavor_mal.9.d
	picture = MALI_DECLINE_eventPicture

	is_triggered_only = yes
	major = yes

	immediate = {
		hidden_effect = {
			add_stability = -1
			set_country_flag = started_decline_of_mali
		}
	}

	option = {
		name = flavor_mal.9.a
		tooltip = {
			add_stability = -1
		}

		ai_chance = {
			factor = 1
		}
	}
}

# Disaster ends
country_event = {
	id = flavor_mal.10
	title = flavor_mal.10.t
	desc = flavor_mal.10.d
	picture = MALI_RULER_eventPicture

	is_triggered_only = yes
	major = yes

	immediate = {
		hidden_effect = {
			set_country_flag = had_decline_of_mali
			clr_country_flag = started_decline_of_mali
			clr_country_flag = mal_disaster_province_attempted_independence
			clr_country_flag = mal_disaster_independence_attempt
			clr_country_flag = mal_disaster_had_vassal_punishment
			clr_country_flag = mal_disaster_peasants_rose
			clr_country_flag = mal_disaster_had_scandal
			every_owned_province = {
				limit = {
					OR = {
						has_province_modifier = mal_nobles_take_over
						has_province_modifier = mal_burghers_take_over
					}
				}
				remove_province_modifier = mal_nobles_take_over
				remove_province_modifier = mal_burghers_take_over
			}
			remove_country_modifier = mal_radical_clergy
			remove_country_modifier = mal_radical_dhimmi
			remove_country_modifier = mal_the_declining_authority_of_mali
		}
	}

	option = {
		name = flavor_mal.10.a
		add_stability = 1

		ai_chance = {
			factor = 1
		}
	}
}

# Pretender to Mali
country_event = {
	id = flavor_mal.11
	title = flavor_mal.11.t
	desc = flavor_mal.11.d
	picture = AFRICAN_BAD_WITH_MONARCH_eventPicture
	goto = mal_pretender_province
	is_triggered_only = yes
	
	trigger = {
		has_disaster = decline_of_mali
		NOT = { has_country_flag = mal_disaster_no_pretender_events }
		any_owned_province = {
			region = niger_region
			controlled_by = ROOT
		}
		OR = {
			NOT = { has_ruler_flag = mal_had_pretender_rebels_in_life }
			had_ruler_flag = {
				flag = mal_had_pretender_rebels_in_life
				days = 7300
			}
		}
		had_country_flag = {
			flag = started_decline_of_mali
			days = 3650
		}
	}
	immediate = {
		hidden_effect = {
			set_saved_name = {
				key = mal_pretender
				type = leader
			}
			random_owned_province = {
				limit = {
					region = niger_region
					controlled_by = ROOT
				}
				save_event_target_as = mal_pretender_province
				spawn_rebels = {
					type = pretender_rebels
					leader = mal_pretender
					size = 2
				}
			}
			clr_ruler_flag = mal_had_pretender_rebels_in_life
			set_ruler_flag = mal_had_pretender_rebels_in_life
		}
	}
	
	option = {
		name = flavor_mal.11.a
		tooltip = {
			event_target:mal_pretender_province = {
				spawn_rebels = {
					type = pretender_rebels
					leader = mal_pretender
					size = 2
				}
			}
		}
	}
}

# Nobles Estate revolt in [area]
country_event = {
	id = flavor_mal.12
	title = flavor_mal.12.t
	desc = flavor_mal.12.d
	picture = AFRICAN_REVOLT_eventPicture
	goto = mal_disaster_estate_province
	is_triggered_only = yes
	
	trigger = {
		any_owned_province = {
			is_state = yes
			NOT = { has_province_modifier = mal_nobles_take_over }
		}
		NOT = { has_country_flag = mal_disaster_no_estate_events }
		has_estate = estate_nobles
		estate_influence = {
			estate = estate_nobles
			influence = 30
		}
		NOT = {
			estate_loyalty = {
				estate = estate_nobles
				loyalty = 40
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_state = yes
					NOT = { has_province_modifier = mal_nobles_take_over }
				}
				save_event_target_as = mal_disaster_estate_province
			}
		}
	}
	
	option = {
		name = flavor_mal.12.a
		ai_chance = { factor = 1 }
		event_target:mal_disaster_estate_province = {
			spawn_rebels = {
				type = noble_rebels
				size = 1
			}
		}
		add_estate_loyalty = {
			estate = estate_nobles
			loyalty = -10
		}
	}
	option = {
		name = flavor_mal.12.b
		ai_chance = { factor = 0 }
		event_target:mal_disaster_estate_province = {
			area = {
				limit = {
					owned_by = ROOT
				}
				add_local_autonomy = 15
			}
			add_province_modifier = {
				name = mal_nobles_take_over
				duration = 1825
			}
		}
		add_estate_loyalty = {
			estate = estate_nobles
			loyalty = 5
		}
		change_estate_land_share = {
			estate = estate_nobles
			share = 2
		}
	}
}

# Clergy Estate revolt in [area]
country_event = {
	id = flavor_mal.13
	title = flavor_mal.13.t
	desc = flavor_mal.13.d
	picture = AFRICAN_REVOLT_eventPicture
	goto = mal_disaster_estate_province
	is_triggered_only = yes
	
	trigger = {
		any_owned_province = {
			is_state = yes
			religion = ROOT
		}
		NOT = { has_country_flag = mal_disaster_no_estate_events }
		has_estate = estate_church
		estate_influence = {
			estate = estate_church
			influence = 30
		}
		religion_group = muslim
		NOT = {
			estate_loyalty = {
				estate = estate_church
				loyalty = 40
			}
		}
		NOT = { has_country_modifier = mal_radical_clergy }
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_state = yes
					religion = ROOT
				}
				save_event_target_as = mal_disaster_estate_province
			}
		}
	}
	
	option = {
		name = flavor_mal.13.a
		ai_chance = { factor = 1 }
		event_target:mal_disaster_estate_province = {
			spawn_country_religious_rebels = {
				size = 1
			}
		}
		add_estate_loyalty = {
			estate = estate_church
			loyalty = -10
		}
		if = {
			limit = {
				has_estate = estate_dhimmi
			}
			add_estate_loyalty = {
				estate = estate_dhimmi
				loyalty = 5
			}
		}
	}
	option = {
		name = flavor_mal.13.b
		ai_chance = { factor = 0 }
		add_country_modifier = {
			name = mal_radical_clergy
			duration = 1825
		}
		change_estate_land_share = {
			estate = estate_church
			share = 2
		}
		add_estate_loyalty = {
			estate = estate_church
			loyalty = 5
		}
		if = {
			limit = {
				has_estate = estate_dhimmi
			}
			add_estate_loyalty = {
				estate = estate_dhimmi
				loyalty = -10
			}
		}
	}
}

# Dhimmi Estate revolt in [area]
country_event = {
	id = flavor_mal.14
	title = flavor_mal.14.t
	desc = flavor_mal.14.d
	picture = AFRICAN_REVOLT_eventPicture
	goto = mal_disaster_estate_province
	is_triggered_only = yes
	
	trigger = {
		any_owned_province = {
			is_state = yes
			NOT = { religion = ROOT }
		}
		NOT = { has_country_flag = mal_disaster_no_estate_events }
		NOT = { has_country_modifier = mal_radical_dhimmi }
		religion_group = muslim
		has_estate = estate_dhimmi
		estate_influence = {
			estate = estate_dhimmi
			influence = 30
		}
		NOT = {
			estate_loyalty = {
				estate = estate_dhimmi
				loyalty = 40
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_state = yes
					NOT = { religion = ROOT }
				}
				save_event_target_as = mal_disaster_estate_province
			}
		}
	}
	
	option = {
		name = flavor_mal.14.a
		ai_chance = { factor = 1 }
		event_target:mal_disaster_estate_province = {
			spawn_province_religious_rebels = {
				size = 1
			}
		}
		add_estate_loyalty = {
			estate = estate_dhimmi
			loyalty = -10
		}
		if = {
			limit = {
				has_estate = estate_church
			}
			add_estate_loyalty = {
				estate = estate_church
				loyalty = 5
			}
		}
	}
	option = {
		name = flavor_mal.14.b
		ai_chance = { factor = 0 }
		event_target:mal_disaster_estate_province = {
			area = {
				limit = {
					owned_by = ROOT
				}
				add_local_autonomy = 15
			}
		}
		add_country_modifier = {
			name = mal_radical_dhimmi
			duration = 1825
		}
		change_estate_land_share = {
			estate = estate_dhimmi
			share = 2
		}
		add_estate_loyalty = {
			estate = estate_dhimmi
			loyalty = 5
		}
		if = {
			limit = {
				has_estate = estate_church
			}
			add_estate_loyalty = {
				estate = estate_church
				loyalty = -10
			}
		}
	}
}

# Burgher Estate revolt in [area]
country_event = {
	id = flavor_mal.15
	title = flavor_mal.15.t
	desc = flavor_mal.15.d
	picture = AFRICAN_REVOLT_eventPicture
	goto = mal_disaster_estate_province
	is_triggered_only = yes
	
	trigger = {
		any_owned_province = {
			is_state = yes
			NOT = { has_province_modifier = mal_burghers_take_over }
		}
		NOT = { has_country_flag = mal_disaster_no_estate_events }
		has_estate = estate_burghers
		estate_influence = {
			estate = estate_burghers
			influence = 30
		}
		NOT = {
			estate_loyalty = {
				estate = estate_burghers
				loyalty = 40
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_state = yes
					NOT = { has_province_modifier = mal_burghers_take_over }
				}
				save_event_target_as = mal_disaster_estate_province
			}
		}
	}
	
	option = {
		name = flavor_mal.15.a
		ai_chance = { factor = 1 }
		event_target:mal_disaster_estate_province = {
			spawn_rebels = {
				type = particularist_rebels
				size = 1
			}
		}
		add_estate_loyalty = {
			estate = estate_burghers
			loyalty = -10
		}
	}
	option = {
		name = flavor_mal.15.b
		ai_chance = { factor = 0 }
		event_target:mal_disaster_estate_province = {
			area = {
				limit = {
					owned_by = ROOT
				}
				add_local_autonomy = 15
			}
			add_province_modifier = {
				name = mal_burghers_take_over
				duration = 1825
			}
		}
		add_estate_loyalty = {
			estate = estate_burghers
			loyalty = 5
		}
		change_estate_land_share = {
			estate = estate_burghers
			share = 2
		}
	}
}

# Province declares independence
country_event = {
	id = flavor_mal.16
	title = flavor_mal.16.t
	desc = flavor_mal.16.d
	picture = AFRICAN_REVOLT_eventPicture
	goto = mal_disaster_independent_province
	is_triggered_only = yes
	
	trigger = {
		any_owned_province = {
			any_core_country = {
				is_neighbor_of = ROOT
			}
		}
		NOT = { has_country_flag = mal_appeased_kaabu }
		OR = {
			NOT = { has_country_flag = mal_disaster_province_attempted_independence }
			had_country_flag = {
				flag = mal_disaster_province_attempted_independence
				days = 2920
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			clr_country_flag = mal_disaster_province_attempted_independence
			set_country_flag = mal_disaster_province_attempted_independence
			random_owned_province = {
				limit = {
					any_core_country = {
						is_neighbor_of = ROOT
					}
				}
				random_core_country = {
					limit = {
						is_neighbor_of = ROOT
					}
					save_event_target_as = mal_original_owner
				}
			}
			random_owned_province = {
				limit = {
					is_core = event_target:mal_original_owner
				}
				save_event_target_as = mal_disaster_independent_province
			}
		}
	}
	
	option = {
		name = flavor_mal.16.a
		ai_chance = { factor = 1 }
		event_target:mal_disaster_independent_province = {
			spawn_rebels = {
				type = nationalist_rebels 
				size = 1
				friend = event_target:mal_original_owner
			}
		}
	}
	option = {
		name = flavor_mal.16.b
		ai_chance = { factor = 0 }
		event_target:mal_disaster_independent_province = {
			cede_province = event_target:mal_original_owner
		}
		add_prestige = -10
	}
}

# Kaabu declares independence
country_event = {
	id = flavor_mal.17
	title = flavor_mal.17.t
	desc = flavor_mal.17.d
	picture = AFRICAN_REVOLT_eventPicture
	goto = mal_disaster_province_of_kbu
	is_triggered_only = yes
	fire_only_once = yes
	
	trigger = {
		NOT = { exists = KBU }
		any_owned_province = {
			is_core = KBU
		}
		NOT = { has_country_flag = mal_appeased_kaabu }
		OR = {
			NOT = { has_country_flag = mal_disaster_independence_attempt }
			had_country_flag = {
				flag = mal_disaster_independence_attempt
				days = 2190
			}
		}
		had_country_flag = {
			flag = started_decline_of_mali
			days = 730
		}
	}
	
	immediate = {
		hidden_effect = {
			clr_country_flag = mal_disaster_independence_attempt
			set_country_flag = mal_disaster_independence_attempt
			random_owned_province = {
				limit = {
					is_core = KBU
				}
				save_event_target_as = mal_disaster_province_of_kbu
			}
		}
	}
	
	option = {
		name = flavor_mal.17.a
		ai_chance = { factor = 1 }
		event_target:mal_disaster_province_of_kbu = {
			spawn_rebels = {
				type = nationalist_rebels 
				size = 4
				friend = KBU
			}
		}
	}
	option = {
		name = flavor_mal.17.b
		ai_chance = { factor = 0 }
		release = KBU
	}
}

# Jolof declares independence
country_event = {
	id = flavor_mal.18
	title = flavor_mal.18.t
	desc = flavor_mal.18.d
	picture = AFRICAN_REVOLT_eventPicture
	goto = mal_disaster_province_of_jol
	is_triggered_only = yes
	fire_only_once = yes
	
	trigger = {
		NOT = { exists = JOL }
		any_owned_province = {
			is_core = JOL
		}
		NOT = { has_country_flag = mal_appeased_kaabu }
		OR = {
			NOT = { has_country_flag = mal_disaster_independence_attempt }
			had_country_flag = {
				flag = mal_disaster_independence_attempt
				days = 2190
			}
		}
	}
	
	immediate = {
		clr_country_flag = mal_disaster_independence_attempt
		set_country_flag = mal_disaster_independence_attempt
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_core = JOL
				}
				save_event_target_as = mal_disaster_province_of_jol
			}
		}
	}
	
	option = {
		name = flavor_mal.18.a
		ai_chance = { factor = 1 }
		event_target:mal_disaster_province_of_jol = {
			spawn_rebels = {
				type = nationalist_rebels 
				size = 4
				friend = JOL
			}
		}
	}
	option = {
		name = flavor_mal.18.b
		ai_chance = { factor = 0 }
		release = JOL
	}
}

# Jenne fights against Mali occupation
country_event = {
	id = flavor_mal.19
	title = flavor_mal.19.t
	desc = flavor_mal.19.d
	picture = AFRICAN_REVOLT_eventPicture
	goto = mal_disaster_province_of_jnn
	is_triggered_only = yes
	fire_only_once = yes
	
	trigger = {
		NOT = { exists = JNN }
		any_owned_province = {
			is_core = JNN
		}
		NOT = { has_country_flag = mal_appeased_kaabu }
		OR = {
			NOT = { has_country_flag = mal_disaster_independence_attempt }
			had_country_flag = {
				flag = mal_disaster_independence_attempt
				days = 2190
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			clr_country_flag = mal_disaster_independence_attempt
			set_country_flag = mal_disaster_independence_attempt
			random_owned_province = {
				limit = {
					is_core = JNN
				}
				save_event_target_as = mal_disaster_province_of_jnn
			}
		}
	}
	
	option = {
		name = flavor_mal.19.a
		ai_chance = { factor = 1 }
		event_target:mal_disaster_province_of_jnn = {
			spawn_rebels = {
				type = nationalist_rebels 
				size = 4
				friend = JNN
			}
		}
	}
	option = {
		name = flavor_mal.19.b
		ai_chance = { factor = 0 }
		release = JNN
	}
}

# Kongs fights against Mali occupation
country_event = {
	id = flavor_mal.20
	title = flavor_mal.20.t
	desc = flavor_mal.20.d
	picture = AFRICAN_REVOLT_eventPicture
	goto = mal_disaster_province_of_kng
	is_triggered_only = yes
	
	trigger = {
		NOT = { exists = KNG }
		any_owned_province = {
			is_core = KNG
		}
		NOT = { has_country_flag = mal_appeased_kaabu }
		OR = {
			NOT = { has_country_flag = mal_disaster_independence_attempt }
			had_country_flag = {
				flag = mal_disaster_independence_attempt
				days = 2190
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			clr_country_flag = mal_disaster_independence_attempt
			set_country_flag = mal_disaster_independence_attempt
			random_owned_province = {
				limit = {
					is_core = KNG
				}
				save_event_target_as = mal_disaster_province_of_kng
			}
		}
	}
	
	option = {
		name = flavor_mal.20.a
		ai_chance = { factor = 1 }
		event_target:mal_disaster_province_of_kng = {
			spawn_rebels = {
				type = nationalist_rebels 
				size = 4
				friend = KNG
			}
		}
	}
	option = {
		name = flavor_mal.20.b
		ai_chance = { factor = 0 }
		release = KNG
	}
}

# Subjects don't recognize Mali
country_event = {
	id = flavor_mal.21
	title = flavor_mal.21.t
	desc = flavor_mal.21.d
	picture = AFRICAN_BAD_WITH_MONARCH_eventPicture

	is_triggered_only = yes
	trigger = {
		num_of_subjects = 1
		NOT = { has_country_modifier = mal_the_declining_authority_of_mali }
		OR = {
			NOT = { has_country_flag = mal_disaster_had_vassal_punishment }
			had_country_flag = {
				flag = mal_disaster_had_vassal_punishment
				days = 14600
			}
		}
	}

	immediate = {
		hidden_effect = {
			clr_country_flag = mal_disaster_had_vassal_punishment
			set_country_flag = mal_disaster_had_vassal_punishment
		}
	}

	option = {
		name = flavor_mal.21.a
		add_country_modifier = {
			name = mal_the_declining_authority_of_mali
			duration = 9125
		}

		ai_chance = {
			factor = 1
		}
	}
}

# Peasants revolt in [area]
country_event = {
	id = flavor_mal.22
	title = flavor_mal.22.t
	desc = flavor_mal.22.d
	picture = AFRICAN_REVOLT_eventPicture
	goto = mal_disaster_peasant_province
	is_triggered_only = yes
	
	trigger = {
		any_owned_province = {
			is_state = yes
			is_capital = no
		}
		OR = {
			NOT = { has_country_flag = mal_disaster_peasants_rose }
			had_country_flag = {
				flag = mal_disaster_peasants_rose
				days = 720
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			clr_country_flag = mal_disaster_peasants_rose
			set_country_flag = mal_disaster_peasants_rose
			random_owned_province = {
				limit = {
					is_state = yes
					is_capital = no
				}
				save_event_target_as = mal_disaster_peasant_province
			}
		}
	}
	
	option = {
		name = flavor_mal.22.a
		ai_chance = { factor = 0 }
		event_target:mal_disaster_peasant_province = {
			spawn_rebels = {
				type = anti_tax_rebels
				size = 2
			}
		}
	}
	option = {
		name = flavor_mal.22.b
		ai_chance = { factor = 1 }
		event_target:mal_disaster_peasant_province = {
			area = {
				limit = {
					owned_by = ROOT
				}
				add_local_autonomy = 30
			}
		}
	}
}

# Scandal in [Root.GetName]
country_event = {
	id = flavor_mal.23
	title = flavor_mal.23.t
	desc = flavor_mal.23.d
	picture = AFRICAN_BAD_WITH_MONARCH_eventPicture
	is_triggered_only = yes
	
	trigger = {
		stability = -2
		OR = {
			NOT = { has_country_flag = mal_disaster_had_scandal }
			had_country_flag = {
				flag = mal_disaster_had_scandal
				days = 1195
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			clr_country_flag = mal_disaster_had_scandal
			set_country_flag = mal_disaster_had_scandal
			add_stability = -1
		}
	}
	
	option = {
		name = flavor_mal.23.a
		ai_chance = { factor = 1 }
		tooltip = {
			add_stability = -1
		}
	}
}

#The quest for Muhammad ibn Qu's lost fleet
country_event = {
	id = flavor_mal.24
	title = flavor_mal.24.t
	desc = flavor_mal.24.desc
	picture = BARBARY_PIRATES_eventPicture

	is_triggered_only = yes

	option = {
		name = flavor_mal.24.a
		
		create_explorer = {
			tradition = 40
		}
		add_sailors = 5000
		ai_chance = {
			factor = 1
		}
	}
}

#NEW LAND!
country_event = {
	id = flavor_mal.25
	title = flavor_mal.25.t
	desc = flavor_mal.25.desc
	picture = AFRICAN_EXPLORER_eventPicture

	is_triggered_only = yes

	option = {
		name = flavor_mal.25.a
		if = {
			limit = {
				755 = {
					OR = {
						owner = {	#Mission reward should be not ruined by some native OPM
							was_player = no
							ai = yes
							NOT = { num_of_cities = 2 }

						}
						is_empty = yes
					}
				}
			}
			add_sailors = -1000	#They are now settling the province
		}
		755 = {
			if = {
				limit = {
					OR = {
						owner = {	#Mission reward should be not ruined by some native OPM
							was_player = no
							ai = yes
							NOT = { num_of_cities = 2 }

						}
						is_empty = yes
					}
				}
				cede_province = ROOT
				add_core = ROOT
				add_base_tax = 2
				add_base_production = 2
				add_base_manpower = 1
				change_religion = ROOT
				change_culture = ROOT
			}
			else = {
				add_core = ROOT
			}
		}

		colonial_brazil = {
			add_permanent_claim = ROOT
		}

		ai_chance = {
			factor = 1
		}
	}
}

#Mali goes full out on ivory trade
country_event = {
	id = flavor_mal.26
	title = flavor_mal.26.t
	desc = flavor_mal.26.desc
	picture = AFRICAN_EUROPEAN_PURCHASE_eventPicture

	is_triggered_only = yes

	option = {	#Ivory trade!
		name = flavor_mal.26.a
		add_years_of_owned_provinces_production_income = {
			years = 3
			trigger = {
				trade_goods = ivory
			}
			custom_tooltip = MONOPOLY_INCOME_IVORY_DESC
		}
		change_price = {
			trade_goods = ivory
			key = MALI_IVORY
			value = 0.33
			duration = 7300
		}
		hidden_effect = {
			every_country = {
				limit = {
					ai = no
				}
				country_event = {
					id = flavor_mal.27
				}
			}
		}

		ai_chance = {
			factor = 1
		}
	}
}

#Info for other players that Ivory has increased price
country_event = {
	id = flavor_mal.27
	title = flavor_mal.27.t
	desc = flavor_mal.27.desc
	picture = TRADEGOODS_eventPicture

	is_triggered_only = yes

	option = {	#Ivory trade!
		name = flavor_mal.27.a
		tooltip = {
			change_price = {
				trade_goods = ivory
				key = MALI_IVORY
				value = 0.33
				duration = 7300
			}
		}

		ai_chance = {
			factor = 1
		}
	}
}

#Reconquest of the city of Timbuktu
country_event = {
	id = flavor_mal.28
	title = flavor_mal.28.t
	desc = flavor_mal.28.desc
	picture = AFRICAN_FIGHT_EUROPEANS_eventPicture

	is_triggered_only = yes

	option = {	#Move capital to Timbuktu
		name = flavor_mal.28.a
		set_capital = 1132
		1132 = {
			add_base_tax = 2
			add_base_production = 2
			add_base_manpower = 1
		}
		if = {
			limit = {
				1127 = {
					is_empty = yes
				}
			}
			custom_tooltip = can_colonize_the_strait_tt
			hidden_effect = {
				set_country_flag = can_colonize_the_strait
			}
		}

		ai_chance = {
			factor = 1
		}
	}

	option = {	#Develop own capital instead
		name = flavor_mal.28.b
		capital_scope = {
			add_base_tax = 2
			add_base_production = 2
			add_base_manpower = 1
		}
		if = {
			limit = {
				1127 = {
					is_empty = yes
				}
			}
			custom_tooltip = can_colonize_the_strait_tt
			hidden_effect = {
				set_country_flag = can_colonize_the_strait
			}
		}

		ai_chance = {
			factor = 0
		}
	}
}

#The Great Mosque of Djenné
country_event = {
	id = flavor_mal.29
	title = flavor_mal.29.t
	desc = flavor_mal.29.desc
	picture = MOSQUE_eventPicture

	is_triggered_only = yes

	option = {
		name = flavor_mal.29.a
		1134 = {
			change_religion = ROOT
			add_base_tax = 2
			add_base_production = 2
			if = {
				limit = {
					has_dlc = "Leviathan"
				}
				set_great_project_tier_2 = {
					type = great_mosque_djenne
				}
			}
			else = {
				add_province_triggered_modifier = great_mosque_djenne_modifier
			}
		}

		ai_chance = {
			factor = 1
		}
	}
}

#Reintegrate of Songhai
country_event = {
	id = flavor_mal.30
	title = flavor_mal.30.t
	desc = flavor_mal.30.desc
	picture = SONGHAI_eventPicture

	is_triggered_only = yes

	option = {
		name = flavor_mal.30.a
		add_accepted_culture = songhai
		custom_tooltip = flavor_mal.30.a.tt
		hidden_effect = {
			every_owned_province = {
				limit = {
					culture = songhai
				}
				add_nationalism = -30
			}
		}

		ai_chance = {
			factor = 1
		}
	}
}

#Invest money into Maghreb to gain favorable allies
country_event = {
	id = flavor_mal.31
	title = flavor_mal.31.t
	desc = flavor_mal.31.desc
	picture = SAHARA_eventPicture

	is_triggered_only = yes

	option = {	#Send a gold gift to the Maghreb people
		name = flavor_mal.31.a
		add_treasury = -400
		every_country = {
			limit = {
				capital_scope = {
					region = maghreb_region
				}
				religion_group = ROOT
			}
			add_opinion = {
				who = ROOT
				modifier = mal_gold_of_mali
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				NOT = { treasury = 450 }
			}
			modifier = {
				factor = 0
				NOT = {
					calc_true_if = {
						all_country = {
							capital_scope = {
								region = maghreb_region
							}
							religion_group = ROOT
						}
						amount = 1
					}
				}
			}
		}
	}

	option = {	#Send an ivory gift to the Maghreb people
		name = flavor_mal.31.b
		add_treasury = -200
		every_country = {
			limit = {
				capital_scope = {
					region = maghreb_region
				}
				religion_group = ROOT
			}
			add_opinion = {
				who = ROOT
				modifier = mal_ivory_of_mali
			}
		}

		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				NOT = { treasury = 250 }
			}
			modifier = {
				factor = 0
				NOT = {
					calc_true_if = {
						all_country = {
							capital_scope = {
								region = maghreb_region
							}
							religion_group = ROOT
						}
						amount = 1
					}
				}
			}
		}
	}

	option = {	#Send no gold whatsoever
		name = flavor_mal.31.c
		add_prestige = 10

		ai_chance = {
			factor = 1
			modifier = {
				factor = 0
				treasury = 250
			}
			modifier = {
				factor = 0
				any_country = {
					capital_scope = {
						region = maghreb_region
					}
					religion_group = ROOT
				}
			}
		}
	}
}

#Choose trade colony to purchase
country_event = {
	id = flavor_mal.32
	title = flavor_mal.32.t
	desc = flavor_mal.32.desc
	picture = AFRICAN_EUROPEAN_PURCHASE_eventPicture

	is_triggered_only = yes

	immediate = {
		hidden_effect = {
			clr_country_flag = mal_allowed_to_purchase_trade_colony
		}
	}

	option = { #Try to buy Gibraltar
		name = flavor_mal.32.a
		goto = 226
		trigger = {
			NOT = { owns_or_non_sovereign_subject_of = 226 }
			226 = {
				owner = {
					is_at_war = no
					NOT = { capital = 226 }
				}
			}
		}
		custom_tooltip = flavor_mal.32.a.tt
		hidden_effect = {
			226 = {
				save_global_event_target_as = mal_colony_to_buy
				owner = {
					country_event = {
						id = flavor_mal.33
					}
				}
			}
		}
		mal_determine_offer_acceptance = {
			province = 226
		}

		ai_chance = { 
			factor = 20
		}
	}

	option = { #Try to buy Corsica
		name = flavor_mal.32.b
		goto = 1247
		trigger = {
			NOT = { owns_or_non_sovereign_subject_of = 1247 }
			1247 = {
				owner = {
					is_at_war = no
					NOT = { capital = 1247 }
				}
			}
		}
		custom_tooltip = flavor_mal.32.b.tt
		hidden_effect = {
			1247 = {
				save_global_event_target_as = mal_colony_to_buy
				owner = {
					country_event = {
						id = flavor_mal.33
					}
				}
			}
		}
		mal_determine_offer_acceptance = {
			province = 1247
		}

		ai_chance = { 
			factor = 20
		}
	}

	option = { #Try to buy Malta
		name = flavor_mal.32.c
		goto = 126
		trigger = {
			NOT = { owns_or_non_sovereign_subject_of = 126 }
			126 = {
				owner = {
					is_at_war = no
					NOT = { capital = 126 }
				}
			}
		}
		custom_tooltip = flavor_mal.32.c.tt
		hidden_effect = {
			126 = {
				save_global_event_target_as = mal_colony_to_buy
				owner = {
					country_event = {
						id = flavor_mal.33
					}
				}
			}
		}
		mal_determine_offer_acceptance = {
			province = 126
		}

		ai_chance = { 
			factor = 20
		}
	}

	option = { #Try to buy Minorca
		name = flavor_mal.32.d
		goto = 4559
		trigger = {
			NOT = { owns_or_non_sovereign_subject_of = 4559 }
			4559 = {
				owner = {
					is_at_war = no
					NOT = { capital = 4559 }
				}
			}
		}
		custom_tooltip = flavor_mal.32.d.tt
		hidden_effect = {
			4559 = {
				save_global_event_target_as = mal_colony_to_buy
				owner = {
					country_event = {
						id = flavor_mal.33
					}
				}
			}
		}
		mal_determine_offer_acceptance = {
			province = 4559
		}

		ai_chance = { 
			factor = 20
		}
	}

	option = { #Try to buy Nice
		name = flavor_mal.32.e
		goto = 102
		trigger = {
			NOT = { owns_or_non_sovereign_subject_of = 102 }
			102 = {
				owner = {
					is_at_war = no
					NOT = { capital = 102 }
				}
			}
		}
		custom_tooltip = flavor_mal.32.e.tt
		hidden_effect = {
			102 = {
				save_global_event_target_as = mal_colony_to_buy
				owner = {
					country_event = {
						id = flavor_mal.33
					}
				}
			}
		}
		mal_determine_offer_acceptance = {
			province = 102
		}

		ai_chance = { 
			factor = 20
		}
	}

	option = { #I need more time to think about it
		name = flavor_mal.32.f
		trigger = {
			NOT = { owns_or_non_sovereign_subject_of = 226 }
			NOT = { owns_or_non_sovereign_subject_of = 1247 }
			NOT = { owns_or_non_sovereign_subject_of = 126 }
			NOT = { owns_or_non_sovereign_subject_of = 4559 }
			NOT = { owns_or_non_sovereign_subject_of = 102 }
		}
		custom_tooltip = flavor_mal.32.f.tt
		hidden_effect = {
			set_country_flag = mal_allowed_to_purchase_trade_colony
		}
		
		ai_chance = { 
			factor = 0
		}
	}

	option = { #I already have them all though
		name = flavor_mal.32.g
		trigger = {
			owns_or_non_sovereign_subject_of = 226
			owns_or_non_sovereign_subject_of = 1247
			owns_or_non_sovereign_subject_of = 126
			owns_or_non_sovereign_subject_of = 4559
			owns_or_non_sovereign_subject_of = 102
		}
		highlight = yes
		add_mercantilism = 5
		
		ai_chance = { 
			factor = 100
		}
	}
}

#The gold offer from Mali
country_event = {	
	id = flavor_mal.33
	title = flavor_mal.33.t
	desc = flavor_mal.33.desc
	picture = AFRICAN_EUROPEAN_PURCHASE_eventPicture
	goto = mal_colony_to_buy 
	is_triggered_only = yes
	
	option = {	#Thanks for the money
		name = flavor_mal.33.a
		event_target:mal_colony_to_buy = {
			remove_core = ROOT
			add_core = FROM
			cede_province = FROM
		}
		add_treasury = 2000
		FROM = {
			country_event = {
				id = flavor_mal.34
			}
		}

		ai_chance = { 
			factor = 100
			modifier = {
				factor = 0
				OR = {
					is_rival = FROM
					is_enemy = FROM
				}
			}
			modifier = {
				factor = 0.25
				NOT = {
					has_opinion = {
						who = FROM
						value = 0
					}
				}
			}
			modifier = {
				factor = 0.25
				NOT = {
					has_opinion = {
						who = FROM
						value = -50
					}
				}
			}
			modifier = {
				factor = 0.25
				NOT = {
					has_opinion = {
						who = FROM
						value = -75
					}
				}
			}
			modifier = {
				factor = 0.25
				NOT = {
					has_opinion = {
						who = FROM
						value = -100
					}
				}
			}
			modifier = {
				factor = 0.25
				NOT = {
					has_opinion = {
						who = FROM
						value = -125
					}
				}
			}
			modifier = {
				factor = 0.25
				NOT = {
					has_opinion = {
						who = FROM
						value = -150
					}
				}
			}
			modifier = {
				factor = 0
				NOT = {
					has_opinion = {
						who = FROM
						value = -175
					}
				}
			}
		}
	}
	
	option = {	#Nah
		name = flavor_mal.33.b
		event_target:mal_colony_to_buy = {
			add_core = FROM
		}
		FROM = {
			country_event = {
				id = flavor_mal.35
			}
		}

		ai_chance = { 
			factor = 100
			modifier = {
				factor = 0
				NOT = { is_rival = FROM }
				NOT = { is_enemy = FROM }
			}
			modifier = {
				factor = 0.25
				has_opinion = {
					who = FROM
					value = 0
				}
			}
			modifier = {
				factor = 0.25
				has_opinion = {
					who = FROM
					value = 50
				}
			}
			modifier = {
				factor = 0
				has_opinion = {
					who = FROM
					value = 100
				}
			}
		}
	}
}

#Mali gets the European colony
country_event = {
	id = flavor_mal.34
	title = flavor_mal.34.t
	desc = flavor_mal.34.desc
	picture = AFRICAN_EUROPEAN_PURCHASE_eventPicture
	
	is_triggered_only = yes
	
	option = {	#Lovely
		name = flavor_mal.34.a
		add_treasury = -2000
		tooltip = {
			event_target:mal_colony_to_buy = {
				remove_core = FROM
				add_core = ROOT
				cede_province = ROOT
			}
		}
		ai_chance = { 
			factor = 100
		}
	}

	after = {
		hidden_effect = {
			clear_global_event_target = mal_colony_to_buy
		}
	}
}

#Mali gets refused
country_event = {
	id = flavor_mal.35
	title = flavor_mal.35.t
	desc = flavor_mal.35.desc
	picture = AFRICAN_EUROPEAN_PURCHASE_eventPicture
	
	is_triggered_only = yes
	
	option = {	#Aww... then I must take it by force then
		name = flavor_mal.35.a
		tooltip = {
			event_target:mal_colony_to_buy = {
				add_core = ROOT
			}
		}
		ai_chance = { 
			factor = 100
		}
	}

	after = {
		hidden_effect = {
			clear_global_event_target = mal_colony_to_buy
		}
	}
}

#Mali inflates the market of Europe with GOLD - Deprecated
country_event = {
	id = flavor_mal.36
	title = flavor_mal.36.t
	desc = flavor_mal.36.desc
	picture = AN_EMPIRE_FOR_A_GIRAFFE_eventPicture
	
	is_triggered_only = yes
	major = yes
	
	option = {	#Gold for the entire market!
		name = flavor_mal.36.a
		add_treasury = -15000
		custom_tooltip = flavor_mal.36.a.tt
		hidden_effect = {
			every_province = {
				limit = {
					trade_goods = gold
					owner = {
						OR = {
							AND = {
								capital_scope = {
									continent = europe
								}
								is_free_or_tributary_trigger = yes
							}
							AND = {
								is_subject_other_than_tributary_trigger = yes
								overlord = {
									capital_scope = {
										continent = europe
									}
								}
							}
						}
					}
				}
				add_permanent_province_modifier = {
					name = mal_closed_gold_mine
					duration = 5475
				}
			}
			random_province = {
				limit = {
					has_province_modifier = bullion_gold_mining
				}
				remove_province_modifier = bullion_gold_mining
			}
		}
		custom_tooltip = flavor_mal.36.a.at
		hidden_effect = {
			every_country = {
				limit = {
					capital_scope = {
						continent = europe
					}
					ai = yes
					was_player = no
					OR = {
						is_free_or_tributary_trigger = yes
						overlord = {
							ai = yes
							was_player = no
						}
					}
				}
				add_inflation_scaled_to_trade = {
					inflation = 1.5
				}
			}
		}
		if = {
			limit = {
				calc_true_if = {
					all_country = {
						OR = {
							ai = no
							was_player = yes
						}
					}
					amount = 2
				}
			}
			custom_tooltip = flavor_mal.36.a.bt
			hidden_effect = {
				every_country = {
					limit = {
						capital_scope = {
							continent = europe
						}
						OR = {
							ai = no
							was_player = yes
							overlord = {
								OR = {
									ai = no
									was_player = yes
								}
							}
						}
					}
					add_inflation_scaled_to_trade = {
						inflation = 0.15
					}
				}
			}
		}
		add_country_modifier = {
			name = mal_economic_oppression
			duration = 5475
		}
	}
}

#Donation to Mecca and the brethren in faith
country_event = {
	id = flavor_mal.37
	title = flavor_mal.37.t
	desc = flavor_mal.37.desc
	picture = AFRICAN_CARAVAN_eventPicture
	
	is_triggered_only = yes
	
	option = {
		name = flavor_mal.37.a
		add_piety = 0.25
		add_estate_loyalty = {
			estate = estate_church
			loyalty = 20
		}
		add_ruler_personality = zealot_personality
		hidden_effect = {
			add_ruler_personality_ancestor = {
				key = zealot
			}
		}
		if = {
			limit = {
				owns = 385
			}
			385 = {
				add_building_construction = {
					building = cathedral
					speed = 1
					cost = 0
				}
			}
		}
		else = {
			custom_tooltip = flavor_mal.37.a.tt
			hidden_effect = {
				385 = {
					owner = {
						country_event = {
							id = flavor_mal.38
						}
					}
				}
			}
		}
	}
	
	option = {
		name = flavor_mal.37.b
		add_piety = -0.25
		add_estate_loyalty = {
			estate = estate_dhimmi
			loyalty = 20
		}
		add_ruler_personality = kind_hearted_personality
		hidden_effect = {
			add_ruler_personality_ancestor = {
				key = kind_hearted
			}
		}
		if = {
			limit = {
				owns = 385
			}
			385 = {
				add_building_construction = {
					building = counting_house
					speed = 1
					cost = 0
				}
			}
		}
		else = {
			custom_tooltip = flavor_mal.37.b.tt
			hidden_effect = {
				385 = {
					owner = {
						country_event = {
							id = flavor_mal.39
						}
					}
				}
			}
		}
	}
}

#Mecca gains a Great Mosque
country_event = {
	id = flavor_mal.38
	title = flavor_mal.38.t
	desc = flavor_mal.38.desc
	picture = MOSQUE_eventPicture
	
	is_triggered_only = yes
	
	option = {
		name = flavor_mal.38.a
		add_opinion = {
			who = FROM
			modifier = mal_invested_into_mecca
		}
		385 = {
			add_building_construction = {
				building = cathedral
				speed = 1
				cost = 0
			}
		}
		
		ai_chance = {
			factor = 1
		}
	}
}

#Mecca gains a Counting House
country_event = {
	id = flavor_mal.39
	title = flavor_mal.39.t
	desc = flavor_mal.39.desc
	picture = FARMING_eventPicture
	
	is_triggered_only = yes
	
	option = {
		name = flavor_mal.39.a
		add_opinion = {
			who = FROM
			modifier = mal_invested_into_mecca
		}
		385 = {
			add_building_construction = {
				building = counting_house
				speed = 1
				cost = 0
			}
		}
		
		ai_chance = {
			factor = 1
		}
	}
}

#Mansa's Journey
#The pilgrimage goes in this order: Maghreb -> Iberia -> France -> Italy -> South Germany -> Balkans -> Anatolia -> Mashriq -> Arabia -> Horn of Africa -> Home
country_event = {
	id = flavor_mal.40
	title = flavor_mal.40.t
	desc = flavor_mal.40.desc
	picture = AFRICAN_CARAVAN_eventPicture
	is_triggered_only = yes

	option = {	#Let the Mansa go onto the pilgrimage
		name = flavor_mal.40.a
		custom_tooltip = flavor_mal.40.a.tt
		add_country_modifier = {
			name = mal_mansas_journey
			duration = -1
			desc = mal_pilgrimage_desc
		}
		hidden_effect = {
			hidden_effect = {
				set_country_flag = mal_journey_to_maghreb
				country_event = {
					id = flavor_mal.41
					days = 210
				}
			}
		}
		ai_chance = {
			factor = 1
		}
	}

	option = {	#Let the advisors go onto the pilgrimage
		name = flavor_mal.40.b
		custom_tooltip = flavor_mal.40.b.tt
		remove_advisor_by_category = ADM
		remove_advisor_by_category = DIP
		remove_advisor_by_category = MIL
		add_country_modifier = {
			name = mal_advisors_journey
			duration = -1
			desc = mal_pilgrimage_desc
		}
		hidden_effect = {
			set_country_flag = mal_journey_to_maghreb
			country_event = {
				id = flavor_mal.41
				days = 210
			}
		}
		ai_chance = {
			factor = 0
		}
	}

	option = {	#We just take the classical route instead
		name = flavor_mal.40.c
		custom_tooltip = flavor_mal.40.c.tt
		add_country_modifier = {
			name = mal_the_pilgrim
			duration = -1
		}
		if = {
			limit = {
				NOT = { owns = 385 }
			}
			hidden_effect = {
				385 = {
					owner = {
						country_event = {
							id = flavor_mal.48
							days = 515
						}
					}
				}
			}
		}
		else = {
			385 = {
				add_base_tax = 2
				add_base_production = 2
				set_great_project_tier_3 = {
					type = kaaba
				}
			}
		}
		ai_chance = {
			factor = 0
		}
	}
}

#Arriving in a new area
country_event = {
	id = flavor_mal.41
	title = flavor_mal.41.t
	desc = { desc = flavor_mal.41.mansa.maghreb				trigger = { has_country_modifier = mal_mansas_journey has_country_flag = mal_journey_to_maghreb }	}
	desc = { desc = flavor_mal.41.mansa.iberia				trigger = { has_country_modifier = mal_mansas_journey has_country_flag = mal_journey_to_iberia } }
	desc = { desc = flavor_mal.41.mansa.france				trigger = { has_country_modifier = mal_mansas_journey has_country_flag = mal_journey_to_france } }
	desc = { desc = flavor_mal.41.mansa.italy				trigger = { has_country_modifier = mal_mansas_journey has_country_flag = mal_journey_to_italy } }
	desc = { desc = flavor_mal.41.mansa.south_germany		trigger = { has_country_modifier = mal_mansas_journey has_country_flag = mal_journey_to_south_germany } }
	desc = { desc = flavor_mal.41.mansa.balkans				trigger = { has_country_modifier = mal_mansas_journey has_country_flag = mal_journey_to_balkans } }
	desc = { desc = flavor_mal.41.mansa.anatolia			trigger = { has_country_modifier = mal_mansas_journey has_country_flag = mal_journey_to_anatolia } }
	desc = { desc = flavor_mal.41.mansa.mashriq				trigger = { has_country_modifier = mal_mansas_journey has_country_flag = mal_journey_to_mashriq } }
	desc = { desc = flavor_mal.41.mansa.egypt				trigger = { has_country_modifier = mal_mansas_journey has_country_flag = mal_journey_to_egypt } }
	desc = { desc = flavor_mal.41.mansa.arabia				trigger = { has_country_modifier = mal_mansas_journey has_country_flag = mal_journey_to_arabia } }
	desc = { desc = flavor_mal.41.mansa.horn_of_africa		trigger = { has_country_modifier = mal_mansas_journey has_country_flag = mal_journey_to_horn_of_africa } }
	desc = { desc = flavor_mal.41.mansa.home				trigger = { has_country_modifier = mal_mansas_journey has_country_flag = mal_journey_to_home } }
	desc = { desc = flavor_mal.41.advisor.maghreb			trigger = { has_country_modifier = mal_advisors_journey has_country_flag = mal_journey_to_maghreb }	}
	desc = { desc = flavor_mal.41.advisor.iberia			trigger = { has_country_modifier = mal_advisors_journey has_country_flag = mal_journey_to_iberia } }
	desc = { desc = flavor_mal.41.advisor.france			trigger = { has_country_modifier = mal_advisors_journey has_country_flag = mal_journey_to_france } }
	desc = { desc = flavor_mal.41.advisor.italy				trigger = { has_country_modifier = mal_advisors_journey has_country_flag = mal_journey_to_italy } }
	desc = { desc = flavor_mal.41.advisor.south_germany		trigger = { has_country_modifier = mal_advisors_journey has_country_flag = mal_journey_to_south_germany } }
	desc = { desc = flavor_mal.41.advisor.balkans			trigger = { has_country_modifier = mal_advisors_journey has_country_flag = mal_journey_to_balkans } }
	desc = { desc = flavor_mal.41.advisor.anatolia			trigger = { has_country_modifier = mal_advisors_journey has_country_flag = mal_journey_to_anatolia } }
	desc = { desc = flavor_mal.41.advisor.mashriq			trigger = { has_country_modifier = mal_advisors_journey has_country_flag = mal_journey_to_mashriq } }
	desc = { desc = flavor_mal.41.advisor.egypt				trigger = { has_country_modifier = mal_advisors_journey has_country_flag = mal_journey_to_egypt } }
	desc = { desc = flavor_mal.41.advisor.arabia			trigger = { has_country_modifier = mal_advisors_journey has_country_flag = mal_journey_to_arabia } }
	desc = { desc = flavor_mal.41.advisor.horn_of_africa	trigger = { has_country_modifier = mal_advisors_journey has_country_flag = mal_journey_to_horn_of_africa } }
	desc = { desc = flavor_mal.41.advisor.home				trigger = { has_country_modifier = mal_advisors_journey has_country_flag = mal_journey_to_home } }
	picture = { 
		picture = BANKRUPTCY_eventPicture
		trigger = { 
			NOT = { has_country_flag = mal_journey_to_maghreb }
			NOT = { has_country_flag = mal_journey_to_iberia }
			NOT = { has_country_flag = mal_journey_to_france }
			NOT = { has_country_flag = mal_journey_to_italy }
			NOT = { has_country_flag = mal_journey_to_south_germany }
			NOT = { has_country_flag = mal_journey_to_balkans }
			NOT = { has_country_flag = mal_journey_to_anatolia }
			NOT = { has_country_flag = mal_journey_to_mashriq }
			NOT = { has_country_flag = mal_journey_to_egypt }
			NOT = { has_country_flag = mal_journey_to_arabia }
			NOT = { has_country_flag = mal_journey_to_horn_of_africa }
			NOT = { has_country_flag = mal_journey_to_home }
		} 
	}
	picture = { picture = muslimgfx_CITY_VIEW_eventPicture	trigger = { has_country_flag = mal_journey_to_maghreb }	}
	picture = { picture = RELIGION_eventPicture				trigger = { has_country_flag = mal_journey_to_iberia } }
	picture = { picture = PRAYING_eventPicture				trigger = { has_country_flag = mal_journey_to_france } }
	picture = { picture = POPE_PREACHING_eventPicture		trigger = { has_country_flag = mal_journey_to_italy } }
	picture = { picture = FREE_CITY_eventPicture			trigger = { has_country_flag = mal_journey_to_south_germany } }
	picture = { picture = MOSQUE_eventPicture				trigger = { has_country_flag = mal_journey_to_balkans } }
	picture = { picture = TUAREG_OTTOMAN_eventPicture		trigger = { has_country_flag = mal_journey_to_anatolia } }
	picture = { picture = BIG_ARABIAN_CITY_eventPicture		trigger = { has_country_flag = mal_journey_to_mashriq } }
	picture = { picture = muslimgfx_RAMADAN_eventPicture	trigger = { has_country_flag = mal_journey_to_egypt } }
	picture = { picture = MECCA_eventPicture				trigger = { has_country_flag = mal_journey_to_arabia } }
	picture = { picture = COPTIC_CITY_eventPicture			trigger = { has_country_flag = mal_journey_to_horn_of_africa } }
	picture = { picture = SAHARA_eventPicture				trigger = { has_country_flag = mal_journey_to_home } }
	is_triggered_only = yes
	trigger = {
		OR = {
			has_country_modifier = mal_mansas_journey
			has_country_modifier = mal_advisors_journey
		}
	}

	immediate = {
		hidden_effect = {
			mal_select_country_for_region = yes
			if = {
				limit = {
					exists = event_target:selected_biggest_country_of_region
				}
				export_to_variable = {
					which = trade_income_variable_tt
					value = trade_income_percentage
					who = event_target:selected_biggest_country_of_region
				}
				multiply_variable = {
					which = trade_income_variable_tt
					value = 100
				}
				#Inflation for target
				multiply_variable = {
					which = trade_income_variable_tt
					value = 0.2
				}
			}
			export_to_variable = {
				which = mal_money_to_give_tt
				value = years_of_income
				who = ROOT
			}
			multiply_variable = {
				which = mal_money_to_give_tt
				value = 2
			}
		}
	}

	option = {	#Be generos
		name = flavor_mal.41.a
		trigger = {
			NOT = { has_country_flag = mal_journey_to_home }
			mal_target_country_exists_in_region = yes
		}
		add_years_of_income = -0.5
		custom_tooltip = flavor_mal.41.a.tt
		hidden_effect = {
			event_target:selected_biggest_country_of_region = {
				set_country_flag = mal_is_already_getting_visit
				country_event = {
					id = flavor_mal.43
				}
			}
			mal_mansa_musa_visit_effect = yes
		}
		#Special case:
		if = {
			limit = {
				has_country_flag = mal_journey_to_arabia
				NOT = { owns = 385 }
			}
			385 = {
				owner = {
					country_event = {
						id = flavor_mal.48
					}
				}
			}
		}
		else_if = {
			limit = {
				has_country_flag = mal_journey_to_arabia
				owns = 385
			}
			385 = {
				add_base_tax = 2
				add_base_production = 2
				set_great_project_tier_3 = {
					type = kaaba
				}
			}
		}
		add_piety = 0.1
		ai_chance = {
			factor = 1
			modifier = {
				NOT = { years_of_income = 3 }
				factor = 0
			}
		}
	}

	option = {	#Be moderate
		name = flavor_mal.41.b
		trigger = {
			NOT = { has_country_flag = mal_journey_to_home }
			mal_target_country_exists_in_region = yes
		}
		add_years_of_income = -0.5
		custom_tooltip = flavor_mal.41.b.tt
		hidden_effect = {
			mal_mansa_musa_visit_effect = yes
		}
		add_piety = 0.05
		#Special case:
		if = {
			limit = {
				has_country_flag = mal_journey_to_arabia
				NOT = { owns = 385 }
			}
			385 = {
				owner = {
					country_event = {
						id = flavor_mal.48
					}
				}
			}
		}
		else_if = {
			limit = {
				has_country_flag = mal_journey_to_arabia
				owns = 385
			}
			385 = {
				add_base_tax = 2
				add_base_production = 2
				set_great_project_tier_3 = {
					type = kaaba
				}
			}
		}
		ai_chance = {
			factor = 1
			modifier = {
				NOT = { years_of_income = 1 }
				factor = 0
			}
		}
	}

	option = {	#Try to not draw attention
		name = flavor_mal.41.c
		trigger = {
			NOT = { has_country_flag = mal_journey_to_home }
			mal_target_country_exists_in_region = yes
		}
		custom_tooltip = flavor_mal.41.c.tt
		add_piety = -0.1
		ai_chance = {
			factor = 1
			modifier = {
				years_of_income = 1
				factor = 0
			}
		}
	}

	option = {	#Glad to be back home
		name = flavor_mal.41.d
		trigger = {
			has_country_flag = mal_journey_to_home
		}
		add_country_modifier = {
			name = mal_the_pilgrim
			duration = -1
		}
		hidden_effect = { clr_country_flag = mal_journey_to_home }
		remove_country_modifier = mal_mansas_journey
		remove_country_modifier = mal_advisors_journey
		ai_chance = {
			factor = 1
		}
	}

	option = {	#Quite nice here (fringe case - nobody has a capital in this region)
		name = flavor_mal.41.e
		trigger = {
			NOT = { has_country_flag = mal_journey_to_home }
			mal_target_country_exists_in_region = no
			mal_owns_provinces_in_region = no
		}
		add_prestige = 15

		ai_chance = {
			factor = 1
		}
	}

	option = {	#Quite nice here (fringe case - Mali is the only worthy power here)
		name = flavor_mal.41.f
		trigger = {
			NOT = { has_country_flag = mal_journey_to_home }
			mal_target_country_exists_in_region = no
			mal_owns_provinces_in_region = yes
		}
		mal_invest_in_own_provinces_effect = yes

		ai_chance = {
			factor = 1
		}
	}

	after = {
		mal_travel_to_next_area = yes
	}
}

#Travelling - Hidden
country_event = {
	id = flavor_mal.42
	title = none
	desc = none
	picture = none
	hidden = yes

	trigger = {
		OR = {
			has_country_modifier = mal_mansas_journey
			has_country_modifier = mal_advisors_journey
		}
		OR = {
			had_country_flag = { flag = mal_journey_to_iberia			days = 120 }
			had_country_flag = { flag = mal_journey_to_france			days = 140 }
			had_country_flag = { flag = mal_journey_to_italy			days = 110 }
			had_country_flag = { flag = mal_journey_to_south_germany	days = 90 }
			had_country_flag = { flag = mal_journey_to_balkans			days = 165 }
			had_country_flag = { flag = mal_journey_to_anatolia			days = 100 }
			had_country_flag = { flag = mal_journey_to_mashriq			days = 70 }
			had_country_flag = { flag = mal_journey_to_egypt			days = 35 }
			had_country_flag = { flag = mal_journey_to_arabia			days = 105 }
			had_country_flag = { flag = mal_journey_to_horn_of_africa	days = 140 }
			had_country_flag = { flag = mal_journey_to_home				days = 365 }
		}
		NOT = { has_country_flag = mal_has_just_arrived }
	}

	mean_time_to_happen = {
		days = 1
	}

	option = {
		if = {
			limit = {
				OR = {
					has_country_modifier = mal_mansas_journey
					has_country_modifier = mal_advisors_journey
				}
			}
			set_country_flag = mal_has_just_arrived
			country_event = {
				id = flavor_mal.41
			}
		}
		ai_chance = {
			factor = 1
		}
	}
}

#The Mansa is visiting - and he is generous!
country_event = {
	id = flavor_mal.43
	title = flavor_mal.43.t
	desc = {
		desc = flavor_mal.43.desc.a
		trigger = {
			FROM = {
				has_country_modifier = mal_mansas_journey
				NOT = { has_country_modifier = mal_advisors_journey }
			}
		}
	}
	desc = {
		desc = flavor_mal.43.desc.b
		trigger = {
			FROM = {
				NOT = { has_country_modifier = mal_mansas_journey }
				has_country_modifier = mal_advisors_journey
			}
		}
	}
	picture = MALI_RULER_eventPicture

	is_triggered_only = yes

	immediate = {
		hidden_effect = {
			export_to_variable = {
				which = mal_money_to_give
				value = years_of_income
				who = FROM
			}
			#multiply_variable = {
			#	which = mal_money_to_give
			#	value = 2
			#}
			set_variable = {
				which = mal_money_to_give_tt
				value = 0
			}
			while = {
				limit = {
					check_variable = {
						which = mal_money_to_give
						value = 1
					}
				}
				subtract_variable = {
					which = mal_money_to_give
					value = 1
				}
				change_variable = {
					which = mal_money_to_give_tt
					value = 1
				}
			}
			export_to_variable = {
				which = trade_income_variable_tt
				value = trade_income_percentage
			}
			multiply_variable = {
				which = trade_income_variable_tt
				value = 100
			}
			#Inflation for target
			multiply_variable = {
				which = trade_income_variable_tt
				value = 0.2
			}
		}
	}

	option = {	#Accept gift
		name = flavor_mal.43.a
		custom_tooltip = flavor_mal.43.a.tt
		add_inflation_scaled_to_trade = {
			custom_tooltip = add_025_inflation
			inflation = 0.2
		}
		add_country_modifier = {
			name = mal_investment_of_the_mansa
			duration = 1825
		}
		add_country_modifier = {
			name = mal_the_gold_inflation
			duration = 1825
		}

		hidden_effect = {
			reverse_add_opinion = {
				who = FROM
				modifier = mal_accepted_gift
			}
			FROM = {
				country_event = {
					id = flavor_mal.44
				}
			}
		}

		ai_chance = {
			factor = 1
		}
	}

	option = {	#Decline
		name = flavor_mal.43.b
		custom_tooltip = flavor_mal.43.b.tt
		add_country_modifier = {
			name = mal_the_gold_inflation
			duration = 1825
		}
		reverse_add_opinion = {
			who = FROM
			modifier = mal_refused_gift
		}
		hidden_effect = {
			FROM = {
				country_event = {
					id = flavor_mal.45
				}
			}
		}

		ai_chance = {
			factor = 0
		}
	}
}

#They accepted our gift!
country_event = {
	id = flavor_mal.44
	title = flavor_mal.44.t
	desc = {
		desc = flavor_mal.44.desc.a
		trigger = {
			FROM = {
				has_country_modifier = mal_mansas_journey
				NOT = { has_country_modifier = mal_advisors_journey }
			}
		}
	}
	desc = {
		desc = flavor_mal.44.desc.b
		trigger = {
			FROM = {
				NOT = { has_country_modifier = mal_mansas_journey }
				has_country_modifier = mal_advisors_journey
			}
		}
	}
	picture = muslimgfx_TRADEGOODS_eventPicture

	is_triggered_only = yes

	immediate = {
		hidden_effect = {
			export_to_variable = {
				which = mal_money_to_give
				value = years_of_income
				who = ROOT
			}
			multiply_variable = {
				which = mal_money_to_give
				value = 2
			}
		}
	}

	option = {	#Yay!
		name = flavor_mal.44.a
		reverse_add_opinion = {
			who = FROM
			modifier = mal_investments_enabled
		}
		transfer_treasury = {
			giver = ROOT
			taker = FROM
			variable = mal_money_to_give
			custom_tooltip = flavor_mal.44.a.tt
		}

		ai_chance = {
			factor = 1
		}
	}
}

#They declined our gift!
country_event = {
	id = flavor_mal.45
	title = flavor_mal.45.t
	desc = {
		desc = flavor_mal.45.desc.a
		trigger = {
			FROM = {
				has_country_modifier = mal_mansas_journey
				NOT = { has_country_modifier = mal_advisors_journey }
			}
		}
	}
	desc = {
		desc = flavor_mal.45.desc.b
		trigger = {
			FROM = {
				NOT = { has_country_modifier = mal_mansas_journey }
				has_country_modifier = mal_advisors_journey
			}
		}
	}
	picture = muslimgfx_TRADEGOODS_eventPicture

	is_triggered_only = yes

	immediate = {
		hidden_effect = {
			FROM = {
				random_neighbor_country = {
					limit = {
						NOT = { has_country_modifier = mal_investment_of_the_mansa }
						NOT = { has_country_modifier = mal_second_target }
						has_country_modifier = mal_the_gold_inflation
					}
					save_event_target_as = mal_next_gold_target
				}
			}
		}
	}

	option = {	#Welp... their misfortune
		name = flavor_mal.45.a

		ai_chance = {
			factor = 1
		}
	}

	option = {	#Maybe somebody else wants it instead
		name = flavor_mal.45.b
		trigger = {
			FROM = {
				NOT = { has_country_modifier = mal_second_target }
			}
		}
		event_target:mal_next_gold_target = {
			country_event = {
				id = flavor_mal.44
			}
			hidden_effect = {
				add_country_modifier = {
					name = mal_second_target
					duration = 365
					hidden = yes
				}
			}
		}
		FROM = {
			random_neighbor_country = {
				limit = {
					NOT = { has_country_modifier = mal_investment_of_the_mansa }
				}
			}
		}
		ai_chance = {
			factor = 0
		}
	}
}

#The Mansa is visiting!
country_event = {
	id = flavor_mal.46
	title = flavor_mal.46.t
	desc = flavor_mal.46.desc
	picture = BANKRUPTCY_eventPicture

	trigger = {
		has_country_modifier = mal_the_gold_inflation
		NOT = { has_country_flag = mal_is_already_getting_visit }
	}

	mean_time_to_happen = {
		days = 1
	}

	option = {	#Oof
		name = flavor_mal.46.a
		tooltip = {
			add_country_modifier = {
				name = mal_the_gold_inflation
				duration = 1825
			}
		}
	}
}

#End of journey - Mansa is dead
country_event = {
	id = flavor_mal.47
	title = flavor_mal.47.t
	desc = flavor_mal.47.desc
	picture = DEATH_OF_HEIR_eventPicture
	is_triggered_only = yes

	trigger = {
		has_country_modifier = mal_mansas_journey
	}

	option = {	#Oh...
		name = flavor_mal.47.a
		custom_tooltip = flavor_mal.47.a.tt
		add_piety = 0.25
		add_country_modifier = {
			name = mal_the_pilgrim
			duration = -1
		}
		remove_country_modifier = mal_mansas_journey
	}
}

#Mansa visits Mecca ... again!
country_event = {
	id = flavor_mal.48
	title = flavor_mal.48.t
	desc = flavor_mal.48.desc
	picture = MALI_RULER_eventPicture
	is_triggered_only = yes

	option = {	#Lovely
		name = flavor_mal.48.a
		385 = {
			add_base_tax = 2
			add_base_production = 2
			set_great_project_tier_3 = {
				type = kaaba
			}
		}
	}
}